<?php
/**
 * 操作日志
 * panglishan
 * 2020.07.27
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class AdminLog extends Model{

    protected $table = 'ln_admin_log';

    protected $primaryKey = 'id';

    protected $fillable
        = [
            "log_id",
            "admin_id",
            "client_ip",
            "dateline",
            "method",
            "uri",
            "action_name",
            "method_name",
            "content",
        ];

    public $timestamps = false;

    //关联用户信息模型
    public function admin()
    {
        return $this->hasOne('App\Models\MainDB\Admin','admin_id','admin_id');
    }

    public function add($request, $content)
    {
        $tmp = explode('/', $request->path());
        $data['admin_id'] = $request->admin_id;
        $data['client_ip'] = $request->server('REMOTE_ADDR');
        $data['dateline'] = time();
        $data['uri'] = $request->path();
        $data['action_name'] = $tmp[count($tmp) - 2];
        $data['method_name'] = $tmp[count($tmp) - 1];
        $data['content'] = $content;
        $this->insert($data);
    }
}